/*
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: OtcMessageApi.java
 *   @Date: 19-1-30 上午11:49
 *   @Author: ppzhao
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 */

package io.bhex.sdk.otc;

import android.text.TextUtils;

import java.io.File;

import io.bhex.baselib.network.BParamsBuilder;
import io.bhex.baselib.network.HttpUtils;
import io.bhex.baselib.network.listener.SimpleResponseListener;
import io.bhex.baselib.network.params.PostParams;
import io.bhex.baselib.network.response.ResultResponse;
import io.bhex.sdk.OTCUrls;
import io.bhex.sdk.otc.bean.OtcMessageResponse;
import io.bhex.sdk.otc.bean.OtcUploadImgResponse;

public class OtcMessageApi {

    /**
     * 聊天记录
     * @param orderId
     * @param startMessageId  非必填 起始消息id 如果不传则取最近的消息
     * @param size
     * @param listener
     */
    public static void messageList(String orderId,String startMessageId,int size,SimpleResponseListener<OtcMessageResponse> listener){
        PostParams params;
        if (TextUtils.isEmpty(startMessageId)) {
            //获取最近消息
            params = BParamsBuilder.post()
                    .url(OTCUrls.OTC_MESSAGE_LIST)
                    .addParam("orderId",orderId)
//                    .addParam("startMessageId",startMessageId)
                    .addParam("size",size)
                    .build();
        }else{
            params = BParamsBuilder.post()
                    .url(OTCUrls.OTC_MESSAGE_LIST)
                    .addParam("orderId",orderId)
                    .addParam("startMessageId",startMessageId)
                    .addParam("size",size)
                    .build();
        }
        HttpUtils.getInstance().request(params,OtcMessageResponse.class,listener);
    }

    /**
     * 发送消息
     * @param orderId
     * @param message  消息
     * @param msgType 消息类型 1：文字 2：图片
     * @param listener
     */
    public static void sendMessage(String orderId,String message,int msgType,SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_MESSAGE_SEND)
                .addParam("orderId",orderId)
                .addParam("message",message)
                .addParam("msgType",msgType)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 上传图片
     * @param imgFilePath 2：图片路径
     * @param listener
     */
    public static void uploadImage(String imgFilePath,SimpleResponseListener<OtcUploadImgResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_UPLOAD_IMAGE)
                .addFile("upload_image_file",new File(imgFilePath))
                .build();
        HttpUtils.getInstance().request(params,OtcUploadImgResponse.class,listener);
    }

    /**
     * 申诉列表
     * @param orderId
     * @param startId
     * @param size
     * @param listener
     */
    public static void appealList(String orderId,String startId,int size,SimpleResponseListener<OtcMessageResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_APPEAL_LIST)
                .addParam("orderId",orderId)
//                .addParam("startMessageId",startMessageId)
//                .addParam("size",size)
                .build();
        HttpUtils.getInstance().request(params,OtcMessageResponse.class,listener);
    }
}
